/**
 * 获取经纬度gps坐标
 * @return {Promise<any>}
 */
let geolocation = function () {
  return new Promise((resolve, reject) => {
    if (!navigator.geolocation) {
      reject('不支持定位，显示默认地址')
    } else {
      let getPosSuccess = function (position) {
        let {latitude, longitude} = position.coords;
        resolve({
          latitude,
          longitude
        })
      };

      let getPosError = function (err) {
        switch (err) {
          case err.PERMISSION_DENIED:
            reject("您拒绝了共享位置，可手动选择城市。");
            break;
          case err.POSITION_UNAVAILABLE:
            break;
          case err.TIMEOUT:
            reject("获取位置超时");
            break;
          default:
            reject("未知错误");
            break;
        }
      };
      navigator.geolocation.getCurrentPosition(getPosSuccess, getPosError, null);
    }
  })
};

export default geolocation
